package fl.ass.service.service.impl;

import cmm.service.core.framework.biz.BaseBizImpl;
import cmm.service.core.framework.dao.IBaseDao;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.fl.mcr.api.IMcrBillMApiService;
import cn.fl.mcr.condition.McrBillMQC;
import cn.fl.mcr.constant.McrBillMConstant;
import cn.fl.mcr.dto.McrBillMDTO;
import fl.ass.facade.condition.AssTrailCarFlowHistoryQC;
import fl.ass.facade.dto.AssTrailCarFlowHistoryDTO;
import fl.ass.service.po.AssTrailCarFlowHistory;
import fl.ass.service.service.IAssTrailCarMcrInsStsService;
import ins.car.facade.car.car.api.IInsModifyApiService;
import ins.car.facade.car.car.api.IInsQueryApiService;
import ins.car.facade.car.car.condition.InsApplicationQC;
import ins.car.facade.car.car.dto.InsApplicationDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * @Description: 拖车信息主表 服务层接口实现
 * @Description: 类中已经实现了简单增删改查操作,可以直接使用,如果有需要重写该方法即可：
 * @Description: 1、add(TVO entity) 2、removeById(Long id) 3、modify(DTO entity) 4、selectById(Long id)	5、searchListPage(Pager page) 7、searchList(DTO dto)   
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class AssTrailCarMcrInsSeviceImpl extends BaseBizImpl<AssTrailCarFlowHistory, AssTrailCarFlowHistoryDTO, AssTrailCarFlowHistoryQC> implements IAssTrailCarMcrInsStsService {
	@Autowired
	private IMcrBillMApiService  mcrBillMApiService;
	@Autowired
	private IInsModifyApiService insModifyApiService;
	@Autowired
	private IInsQueryApiService insQueryApiService;
	private static final Logger log = LoggerFactory.getLogger(IAssTrailCarMcrInsStsService.class);
	@Override
	public boolean updateMrcInsSts(Long cstId) {
		// TODO 自动生成的方法存根
		if(cstId==null){
		    BaseLogUtils.newLogger("更新小贷保险状态失败，cstId是空").info();
			return false;
		}
		try{
			McrBillMQC condition=new McrBillMQC();
			//condition.setCstId(Long.parseLong("180125030000598"));
			condition.setCstId(cstId);
			condition.setLoanStsCd(McrBillMConstant.LOAN_STS_CD_4);
            BaseLogUtils.newLogger("更新小贷保险状态").setKeys("cstId:" + cstId).info();
			List<McrBillMDTO> dtos=mcrBillMApiService.searchMcrBillMList(condition);
			for(McrBillMDTO dto:dtos){
				dto.setLoanStsCd(McrBillMConstant.LOAN_STS_CD_8);
				dto.setStlDt(DateUtils.getCurrentDate(DateUtils.YYYY_MM_DDHHMMSS));
				mcrBillMApiService.modifyMcrBillM(dto);
			}
		
			
			InsApplicationQC insqc=new InsApplicationQC();
			//insqc.setPerId(Long.parseLong("180420165010500"));
			insqc.setPerId(cstId);
			insqc.setLoanState("2");//已放款状态
			//查询保单申请信息
			List<InsApplicationDTO> insapps=insQueryApiService.searchInsPolicyList(insqc);
			List<Long> Ids = new ArrayList<Long>();
			if(CollectionUtils.isNotEmpty(insapps)){
				for(InsApplicationDTO dto:insapps){
					Ids.add(dto.getId());
				}
				
			}
			insModifyApiService.updateInsPayInfo(Ids, "6");
		}catch (Exception e) {
			// TODO: handle exception
			return false;
		}
		return true;
	}
	@Override
	public IBaseDao<AssTrailCarFlowHistory, AssTrailCarFlowHistoryQC> getDao() {
		// TODO 自动生成的方法存根
		return null;
	}
	@Override
	public List<AssTrailCarFlowHistoryDTO> searchList(AssTrailCarFlowHistoryQC condition) throws BaseException {
		// TODO 自动生成的方法存根
		return null;
	}
	
	
	
}

